package com.baizhi.socked;

/**
 *  问： hello 姐
 *  答： 来了，老弟
 *
 *  形成一问一答
 */
public class SockedDemo2 {
    public static void main(String[] args) {
        Object lock = new Object();

        Thread t1 = new Thread(()->{
            synchronized (lock){
                for (int i = 0; i < 20; i++) {
                    System.out.println("Hello，姐");
                    try {
                        Thread.sleep(1000);
                        lock.wait();
                        //lock.notify();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });


        Thread t2 = new Thread(()->{
          synchronized (lock){
              for (int i = 0; i < 20; i++) {
                  System.out.println("来了，老弟");
                  try {
                      Thread.sleep(1000);
                      //lock.notify();
                      lock.notifyAll();

                      lock.wait();
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
              }
          }
        });

        t1.start();
        t2.start();
    }
}
